require.config({
    paths:{
        "text":"../../lib/requireJS/text",
        "jquery":"../../lib/jquery/jquery.min",
        "handlebars":"../../lib/handlebars/handlebars",
        "adminInclude":"../../templates/adminInclude.temp",
        "pageLoader":"../../templates/PageLoader.temp",
        "overLay":"../../templates/OverLay.temp",
        "searchBar":"../../templates/SearchBar.temp",
        "topBar":"../../templates/TopBar.temp",
        "templates":"templates"
    }
});

requirejs(["jquery","templates"],
    function($){
        $.Dpoplar = {};
        $.Dpoplar.options = {
            colors: {
                red: '#F44336',
                pink: '#E91E63',
                purple: '#9C27B0',
                deepPurple: '#673AB7',
                indigo: '#3F51B5',
                blue: '#2196F3',
                lightBlue: '#03A9F4',
                cyan: '#00BCD4',
                teal: '#009688',
                green: '#4CAF50',
                lightGreen: '#8BC34A',
                lime: '#CDDC39',
                yellow: '#ffe821',
                amber: '#FFC107',
                orange: '#FF9800',
                deepOrange: '#FF5722',
                brown: '#795548',
                grey: '#9E9E9E',
                blueGrey: '#607D8B',
                black: '#000000',
                white: '#ffffff'
            },
            leftSideBar: {
                scrollColor: 'rgba(0,0,0,0.5)',
                scrollWidth: '4px',
                scrollAlwaysVisible: false,
                scrollBorderRadius: '0',
                scrollRailBorderRadius: '0'
            },
            dropdownMenu: {
                effectIn: 'fadeIn',
                effectOut: 'fadeOut'
            }
        }

        /*
         * Browser
         * You can manage browser
         */
        var edge = 'Microsoft Edge';
        var ie10 = 'Internet Explorer 10';
        var ie11 = 'Internet Explorer 11';
        var opera = 'Opera';
        var firefox = 'Mozilla Firefox';
        var chrome = 'Google Chrome';
        var safari = 'Safari';

        $.Dpoplar.browser = {
            activate: function () {
                var _this = this;
                var className = _this.getClassName();

                if (className !== '') $('html').addClass(_this.getClassName());
            },
            getBrowser: function () {
                var userAgent = navigator.userAgent.toLowerCase();

                if (/edge/i.test(userAgent)) {
                    return edge;
                } else if (/rv:11/i.test(userAgent)) {
                    return ie11;
                } else if (/msie 10/i.test(userAgent)) {
                    return ie10;
                } else if (/opr/i.test(userAgent)) {
                    return opera;
                } else if (/chrome/i.test(userAgent)) {
                    return chrome;
                } else if (/firefox/i.test(userAgent)) {
                    return firefox;
                } else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
                    return safari;
                }

                return undefined;
            },
            getClassName: function () {
                var browser = this.getBrowser();

                if (browser === edge) {
                    return 'edge';
                } else if (browser === ie11) {
                    return 'ie11';
                } else if (browser === ie10) {
                    return 'ie10';
                } else if (browser === opera) {
                    return 'opera';
                } else if (browser === chrome) {
                    return 'chrome';
                } else if (browser === firefox) {
                    return 'firefox';
                } else if (browser === safari) {
                    return 'safari';
                } else {
                    return '';
                }
            }
        }

        /*
         * Searchbar
         * You can manage the search bar
         */
        var $searchBar = $('.search-bar');
        $.Dpoplar.search = {
            activate: function () {
                var _this = this;

                //Search button click event
                $('.js-search').on('click', function () {
                    _this.showSearchBar();
                });

                //Close search click event
                $searchBar.find('.close-search').on('click', function () {
                    _this.hideSearchBar();
                });

                //ESC key on pressed
                $searchBar.find('input[type="text"]').on('keyup', function (e) {
                    if (e.keyCode == 27) {
                        _this.hideSearchBar();
                    }
                });
            },
            showSearchBar: function () {
                $searchBar.addClass('open');
                $searchBar.find('input[type="text"]').focus();
            },
            hideSearchBar: function () {
                $searchBar.removeClass('open');
                $searchBar.find('input[type="text"]').val('');
            }
        }

        /*
         * Navbar
         * You can manage the navbar
         */
        $.Dpoplar.navbar = {
            activate: function () {
                var $body = $('body');
                var $overlay = $('.overlay');

                //Open left sidebar panel
                $('.bars').on('click', function () {
                    $body.toggleClass('overlay-open');
                    if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
                });

                //Close collapse bar on click event
                $('.nav [data-close="true"]').on('click', function () {
                    var isVisible = $('.navbar-toggle').is(':visible');
                    var $navbarCollapse = $('.navbar-collapse');

                    if (isVisible) {
                        $navbarCollapse.slideUp(function () {
                            $navbarCollapse.removeClass('in').removeAttr('style');
                        });
                    }
                });
            }
        }


        $(document).ready(function(){
            $.Dpoplar.browser.activate();
            //$.Dpoplar.leftSideBar.activate();
            //$.Dpoplar.rightSideBar.activate();
            $.Dpoplar.navbar.activate();
            //$.Dpoplar.dropdownMenu.activate();
            //$.Dpoplar.input.activate();
            //$.Dpoplar.select.activate();
            $.Dpoplar.search.activate();
            setTimeout(function () { $('.page-loader-wrapper').fadeOut(); }, 50);
        });
        
        /*
         * 添加事件监听
         *
        $(document).on("click","#btn2",function(){
            alert("clicked");
        });
         *
         */
    }
);